﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using XiaoGang.Soft.XGWMS.COM;
using XiaoGang.Soft.XGWMS.MODEL;
using XiaoGang.Soft.XGWMS.DAL_SQL;

namespace XiaoGang.Soft.XGWMS.BLL
{
    public class BLL_M006_GOODS_GROUP
    {
        private readonly DAL_SQL.DAL_M006_GOODS_GROUP dal_M006_GOODS_GROUP = new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_M006_GOODS_GROUP();        
        private readonly XiaoGang.Soft.XGWMS.DAL_SQL.DAL_ComProcess dal_ComProcess = new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_ComProcess();
        private readonly XiaoGang.Soft.XGWMS.BLL.BLL_ComProcess bll_ComProcess = new BLL_ComProcess();

        /// <summary>	
        /// <p><b>方法名称</b>GoodsGroupDeleteCheck</p>	
        /// <p><b>概要説明  :</b>检测该分类有没有没使用</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/17</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类编号</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue GoodsGroupDeleteCheck(string strGoodsGroupID)
        {
            return dal_M006_GOODS_GROUP.GoodsGroupDeleteCheck(strGoodsGroupID);
        }

        /// <summary>	
        /// <p><b>方法名称</b>检查不同ID但同名称的商品分类</p>	
        /// <p><b>概要説明  :</b>商品分类名称的检索</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/17</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类名称</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue CheckGoodsGroupNameWithoutID(string GroupID,string GroupName)
        {
            return dal_M006_GOODS_GROUP.CheckGoodsGroupNameWithoutID(GroupID,GroupName);
        }

        /// <summary>
        /// <p><b>方法名称</b>GetSingleData</p>	
        /// <p><b>概要説明  :</b>取得单条商品分类信息</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/08/26</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类信息</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue GetSingleData(MODEL.MOD_M006_GOODS_GROUP model)
        {
            return dal_M006_GOODS_GROUP.GetSingleData(model);
        }

        /// <summary>
        /// <p><b>方法名称</b>SearchProcess</p>	
        /// <p><b>概要説明  :</b>商品分类信息的检索</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/08/26</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类信息</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue SearchProcess(MODEL.MOD_M006_GOODS_GROUP model,bool isShowDelete)
        {
            return dal_M006_GOODS_GROUP.SelectProcess(model, isShowDelete);
        }

        public ReturnValue SearchGoodsNoProcess ( string GoodsID)
        {
            return dal_M006_GOODS_GROUP.SelectGoodsNoProcess (GoodsID);
        }

        /// <summary>
        /// 检查名称是否存在
        /// </summary>
        /// <param name="GroupName"></param>
        /// <returns></returns>
        public ReturnValue CheckName(string GroupName)
        {
            return dal_M006_GOODS_GROUP.CheckName(GroupName); 
        }

        /// <summary>	
        /// <p><b>方法名称</b>InsertProcess</p>	
        /// <p><b>概要説明  :</b>商品分类信息的插入</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/08/26</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类信息</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue AddOrUpdateProcess(MODEL.MOD_M006_GOODS_GROUP model)
        {
            ReturnValue returnValue;

            if (model.GOODS_GROUP_ID != "")
            {
                //更新
                //首先检查不同ID但同名称的用户分组
                returnValue = dal_M006_GOODS_GROUP.CheckGoodsGroupNameWithoutID(model.GOODS_GROUP_ID, model.GOODS_GROUP_NM);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                if (returnValue.ResultDataSet.Tables[0].Rows.Count > 0)
                {
                    return new ReturnValue(false, "W11H01");//本[@]已经存在或已被逻辑删除!
                }
                //检查是否存在该ID的数据
                returnValue = dal_M006_GOODS_GROUP.ExistProcess(model.GOODS_GROUP_ID);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                if (returnValue.ResultDataSet.Tables[0].Rows.Count < 1)
                {
                    return new ReturnValue(false, "W11057");//该数据不存在
                }
                //进行更新
                return dal_M006_GOODS_GROUP.UpdateProcess(model);
            }
            else
            {
                //新添加
                //首先检查名称是否已经存在
                returnValue = dal_M006_GOODS_GROUP.CheckName(model.GOODS_GROUP_NM);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                if (returnValue.ResultDataSet.Tables[0].Rows.Count > 0)
                {
                    return new ReturnValue(false, "W11E01");//本[@]已经存在。
                }
                string UniqueNo = string.Empty;
                if (!DAL_ComProcess.GetUniqueNo(model.UPDATER_ID
                    , model.TERMINAL_CD
                    , "06"
                    , System.DateTime.Now.Year.ToString("####")
                    , out UniqueNo))
                {
                    return new ReturnValue(false, "E11003");//生成业务编号失败
                }
                model.GOODS_GROUP_ID = UniqueNo;
                //进行添加
                return dal_M006_GOODS_GROUP.InsertProcess(model);
            }
        }

        public ReturnValue InsertGoodsNoProcess ( string GoodsID,string GoodsNO )
        {
            return dal_M006_GOODS_GROUP.InsertGoodsNoProcess (GoodsID, GoodsNO);
        }

        /// <summary>	
        /// <p><b>方法名称</b>UpdateProcess</p>	
        /// <p><b>概要説明  :</b>商品分类信息的更新</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/08/26</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类信息</param>
        /// <returns type = "ReturnValue"></returns>
        public string UpdateProcess(MODEL.MOD_M006_GOODS_GROUP model)
        {
            ReturnValue rvReturnValue;           

            rvReturnValue = dal_M006_GOODS_GROUP.UpdateProcess(model);
            if (rvReturnValue.IsSuccess == false)
            {
                return rvReturnValue.ErrorID;
            }
            else
            {
                return "0";
            }
        }

        /// <summary>	
        /// <p><b>方法名称</b>DeleteProcess</p>	
        /// <p><b>概要説明  :</b>商品分类信息的理论删除</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/08/26</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类信息</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue DeleteProcess(MODEL.MOD_M006_GOODS_GROUP model)
        {
            //查询是否存在要删除的数据
            ReturnValue rvReturnValue = dal_M006_GOODS_GROUP.ExistProcess(model.GOODS_GROUP_ID);
            if (!rvReturnValue.IsSuccess)
            {
                return rvReturnValue;
            }
            else
            {
                if (rvReturnValue.ResultDataSet.Tables[0].Rows.Count < 1)
                {
                    rvReturnValue.IsSuccess = false;
                    rvReturnValue.ErrorID = "W11008";//数据不存在!
                    return rvReturnValue;
                }
                else
                {
                    rvReturnValue = dal_M006_GOODS_GROUP.DeleteProcess(model);
                    return rvReturnValue;
                }
            }
        }

        /// <summary>
        /// <p><b>方法名称</b>InsertProcess</p>	
        /// <p><b>概要説明  :</b>商品分类信息的物理删除</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/08/26</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">商品分类信息</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue PhysicalDeleteProcess(string strGoodsGroupID)
        {
            //查询是否存在要删除的数据
            ReturnValue rvReturnValue = dal_M006_GOODS_GROUP.ExistProcess(strGoodsGroupID);
            if (!rvReturnValue.IsSuccess)
            {
                return rvReturnValue;
            }
            else
            {
                if (rvReturnValue.ResultDataSet.Tables[0].Rows.Count < 1)
                {
                    rvReturnValue.IsSuccess = false;
                    rvReturnValue.ErrorID = "W11008";//数据不存在!
                    return rvReturnValue;
                }
                else
                {
                    return dal_M006_GOODS_GROUP.PhysicalDeleteProcess(strGoodsGroupID);
                }
            }
        }

        public ReturnValue DeleteGoodsNoProcess ( string ID )
        {
            return dal_M006_GOODS_GROUP.DeleteGoodsNoProcess(ID);
        }

        /// <summary>
        /// 更新排序
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Updater"></param>
        /// <param name="TERMINAL_CD"></param>
        /// <param name="UpOrDown">小于等于0：向上 大于0：向下</param>
        /// <returns></returns>
        public ReturnValue UpdateOrder(string ID, string Updater, string TERMINAL_CD, int UpOrDown)
        {
            return dal_M006_GOODS_GROUP.UpdateOrder(ID, Updater, TERMINAL_CD, UpOrDown);
        }

    }
}
